package com.ranshiyan.dao;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ranshiyan.entity.User;

public interface UserMapper {
	@Select("SELECT id,username,password,locked,role,create_time createTime "
			+ " FROM cms_user ORDER BY create_time DESC")
	List<User> list();
	
	User getById(Integer userId);
	
	@Update("UPDATE cms_user SET locked=${status} WHERE id=${userId}")
	int updateStatus(@Param("userId") Integer userId,@Param("status") int status);
	
	@Select("SELECT id,username,password,locked,role FROM cms_user WHERE username=#{value}")
	User findByName(String username);
	
	@Insert("INSERT INTO cms_user(username,password,locked,create_time,update_time,role) "
			+ "VALUES(#{username},#{password},0,now(),now(),0)")
	int add(User user);
}
